*** Comparison with other methods

cd ""
clear 
set more off

use data_all_vars_outliers, replace	


*** generates rushing dummies (base and robustness) 
foreach con in none w2_  {
    forvalues dec=5(5)20 {
		local n=1
		foreach var in length_m {
			local pre="`con'"
			if "`con'"=="none" {
				local pre ""
			} 
	
			capture drop `pre'd_pct`dec'_`var'
			gen `pre'd_pct`dec'_`var'=.
			_pctile `pre'`var',nq(100)
			* r1 is 10th percentile, r5 is median, r9 is 90th percentile, r10 is not generated with nq10
			replace  `pre'd_pct`dec'_`var'=1 if `pre'`var'<`r(r`dec')'
			replace  `pre'd_pct`dec'_`var'=0 if `pre'`var'>=`r(r`dec')' & `pre'`var'!=.
			local ++n

			}

	}		
}		
* generates a 0-1 dummy depending on whether the individual is below the base/robustness criterion for rushing on neither wave or at least one wave
foreach var of varlist d_pct* { 
	egen av1_`var'=rowmean(`var' w2_`var')
	replace av1_`var'=2*av1_`var'
	replace av1_`var'=1 if av1_`var'==2
}	
drop d_pct* w2_d_pct*


* standardizing for comparability of coefficients and ease of comparison 
foreach var of varlist extrav consci neurot agree open SOEP_e SOEP_a SOEP_c SOEP_n SOEP_o LS_gen SWLS GPS* cognitive  q_mood_beginning_1 q_mood_end_1 cog_*   {
	sum `var' if `var'!=.
	replace `var'=(`var'-`r(mean)')/`r(sd)' if `var'!=.
	sum w2_`var' if w2_`var'!=.
	replace w2_`var'=(w2_`var'-`r(mean)')/`r(sd)' if w2_`var'!=.
	capture sum w1w2_`var' if w1w2_`var'!=.
	capture replace w1w2_`var'=(w1w2_`var'-`r(mean)')/`r(sd)' if w1w2_`var'!=.	
	}

*** normalize the reliability variables 
*** keep the non-normalized variables as weight_`var'
foreach var of varlist w1w2_sure_pers w1w2_reliable reliable sure_pers w2_reliable w2_sure_pers {
	gen weight_`var'=`var'
	sum `var' if `var'!=.
	replace `var'=(`var'-`r(mean)')/`r(sd)' if `var'!=.
	
	}


* robustness on the cutoff for the BFI question 
gen sure_high4=weight_sure_pers>=4
* robustness on the cutoff for the overall question 
gen rel_high10=weight_reliable==10





*** getting data ready for obviously related instrumental variables (repated measures are used as instruments, "doubles" the data following the procedure outlined in Gillen et al. (2019) online appendix C2
keep if wave2==1
gen id=_n
*replicant==0 are original obs
expand 2, generate(replicant)
gen mainVar = cognitive if replicant == 0
replace mainVar = w2_cognitive if replicant == 1
gen instrument = w2_cognitive if replicant == 0
replace instrument = cognitive if replicant == 1
*One constant per stack
forvalues x=0/1 {
gen constant`x' = replicant == `x'
}



	
******************************************************* Falk et al. (2021) Implementation
* w1w2_variables represent averages across the 2 survey waves
foreach var of varlist BFI2_1-SOEP_extra6 {
	gen w1w2_`var'=(`var'+w2_`var')/2
	* to not lose obs which aren't in w2, just keep the number for w1 - no new information but observations are kept
	replace w1w2_`var'=`var' if w1w2_`var'==.
	}

foreach var of varlist BFI2_1-SOEP_extra6   GPS_risk GPS_time  GPS_pres_bias GPS_alt GPS_trust GPS_pos_rec GPS_neg_rec_self GPS_neg_rec_self2 GPS_neg_rec_other      cog_* {
	sum w1w2_`var', d
	gen n_ik1_`var'=(`var'-`r(mean)')/`r(sd)'
	gen n_ik2_`var'=(w2_`var'-`r(mean)')/`r(sd)'
}

foreach var of varlist  BFI2_1-SOEP_extra6   GPS_risk GPS_time  GPS_pres_bias GPS_alt GPS_trust GPS_pos_rec GPS_neg_rec_self GPS_neg_rec_self2 GPS_neg_rec_other      cog_* {
	gen n_ik_`var'=(n_ik1_`var'+n_ik2_`var')/2
	replace n_ik_`var'=`var' if n_ik_`var'==.
	}

* counts the number of vars (K)	: 82 of them here
local k=1	
foreach var of varlist  BFI2_1-SOEP_extra6   GPS_risk GPS_time  GPS_pres_bias GPS_alt GPS_trust GPS_pos_rec GPS_neg_rec_self GPS_neg_rec_self2 GPS_neg_rec_other      cog_* {
	local ++k
	}
di `k'	

egen numerator_i=rowsd(n_ik_*)

foreach var of varlist BFI2_1-SOEP_extra6   GPS_risk GPS_time  GPS_pres_bias GPS_alt GPS_trust GPS_pos_rec GPS_neg_rec_self GPS_neg_rec_self2 GPS_neg_rec_other      cog_* {
	gen den_sum_t_`var'=(n_ik1_`var'-n_ik_`var')^2+(n_ik2_`var'-n_ik_`var')^2
}
egen den_sum_k=rowtotal(den_sum_t_*)
* division by K(T−1)−2
gen denominator_i=den_sum_k/(80)

* individual self-knowledge according to Falk et al. (2021). Subtract 1/T from num/den
gen pi_i=(numerator_i/denominator_i)-1/2


* like Falk et al. (2021), takes the high category as being above median
gen pi_i_high=(pi_i>1.45)


********************************************************** end of Falk et al. (2021) implementation

	
global w1w2_prefs =" w1w2_GPS_risk w1w2_GPS_time w1w2_GPS_pres_bias w1w2_GPS_neg_rec_self w1w2_GPS_neg_rec_self2 w1w2_GPS_neg_rec_other w1w2_GPS_alt w1w2_GPS_pos_rec  w1w2_GPS_trust"
global w1w2_pers ="w1w2_extrav w1w2_consci w1w2_neurot w1w2_agree w1w2_open"
global w1w2_cognit ="w1w2_cognitive"	

global prefs ="GPS_risk GPS_time GPS_pres_bias GPS_neg_rec_self GPS_neg_rec_self2 GPS_neg_rec_other GPS_alt  GPS_pos_rec GPS_trust"
global pers ="extrav consci neurot agree open"
global cognit ="cognitive"	

global controls ="male age i.country"	

******************************* Exhibits Start ************************************************************************************


**************** Below Generates Table 6 (need to divide number of observations by 2 as each observation here is doubled to enable using the ORIV method)
local i=1
foreach out of varlist 	LS_gen unemp  GPA_pct  college_grad {
	local j=1

	* base
 	reg `out' $pers $prefs $cognit $controls, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, replace dec(2) noomitted

	* regressors averaged over 2 survey waves
 	reg `out' $w1w2_pers $w1w2_prefs $w1w2_cognit $controls, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	
	* excludes observations identified as low quality by the survey provider due to streamlining	
	reg `out' $pers $prefs $cognit $controls if outlier_str!=1 & w2_outlier_str!=1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	* excludes observations identified as low quality by the survey provider on time dimension
	reg `out'  $pers $prefs $cognit $controls if outlier_t!=1 & w2_outlier_t!=1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	* excludes observations identified as low quality by the survey provider
	reg `out' $pers $prefs $cognit $controls if dynata_outliers==0 & dynata_outliers_w2==0, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	

	
	*** no rush
	reg `out'  $pers $prefs $cognit $controls if av1_d_pct5_length_m==0, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	

	* BFI self-reported reliability base
	reg `out' $pers $prefs $cognit $controls if sure_high==1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	
	* BFI self-reported reliability base + no rush
	reg `out' $pers $prefs $cognit $controls if sure_high==1 & av1_d_pct5_length_m==0 , cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted	
	
	* Falk et al. (2021) method
	reg `out'  $pers $prefs $cognit $controls if pi_i_high==1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	
	* Falk et al. (2021) + BFI self-reported reliability base
	reg `out'  $pers $prefs $cognit $controls if pi_i_high==1 & sure_high==1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted

}




**************** Below Generates Table A.15 (need to divide number of observations by 2 as each observation here is doubled to enable using the ORIV method)
local i=1
foreach out of varlist 	LS_gen unemp  GPA_pct  college_grad {
	local j=1

	* base
 	reg `out' $pers $prefs $cognit $controls, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, replace dec(2) noomitted

	* regressors averaged over 2 survey waves
 	reg `out' $w1w2_pers $w1w2_prefs $w1w2_cognit $controls, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	
	* excludes observations identified as low quality by the survey provider due to streamlining	
	reg `out' $pers $prefs $cognit $controls if outlier_str!=1 & w2_outlier_str!=1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	* excludes observations identified as low quality by the survey provider on time dimension
	reg `out'  $pers $prefs $cognit $controls if outlier_t!=1 & w2_outlier_t!=1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	* excludes observations identified as low quality by the survey provider
	reg `out' $pers $prefs $cognit $controls if dynata_outliers==0 & dynata_outliers_w2==0, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	

	
	*** no rush
	reg `out'  $pers $prefs $cognit $controls if av1_d_pct5_length_m==0, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	

	* BFI self-reported reliability base
	reg `out' $pers $prefs $cognit $controls if sure_high==1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	
	* BFI self-reported reliability robustness, less strigent
	reg `out' $pers $prefs $cognit $controls if sure_high4==1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	
	* Overall self-reported reliability at max
	reg `out' $pers $prefs $cognit $controls if rel_high10==1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted

	* Overall self-reported reliability, less strigent
	reg `out' $pers $prefs $cognit $controls if rel_high==1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	
	* BFI self-reported reliability base + no rush
	reg `out' $pers $prefs $cognit $controls if sure_high==1 & av1_d_pct5_length_m==0 , cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted	
	
	* Falk et al. (2021) method
	reg `out'  $pers $prefs $cognit $controls if pi_i_high==1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted
	
	* Falk et al. (2021) + BFI self-reported reliability base
	reg `out'  $pers $prefs $cognit $controls if pi_i_high==1 & sure_high==1, cluster(id) 
	outreg2 using reg_all_`out'_tech_cognitive.xls, append dec(2) noomitted

}

